<% files.each do |file| key = params[:search] ? File.join(file["folder_path"], file["name"]) : file["name"] %>
    <% if file['is_folder'] %>
        <div class="media_item folder_item" data-key="<%= key %>">
          <div class="thumb">
            <i class="fa fa-folder"></i>
          </div>
          <div class="label_thumb">
            <%= file['name'] %>
          </div>
          <% if @show_file_actions %>
              <div class="actions">
                <a href="#" class="del_folder"><i class="fa fa-trash"></i></a>
              </div>
          <% end %>
        </div>
    <% else %>
      <% next if @media_formats.present? && !@media_formats.include?(file["file_type"]) && !@media_formats.include?(file["url"].split('.').last) %>
      <% file['url'] = download_private_file_cama_admin_media_url(file: file[:url]) if params[:private].present? %>
      <div class="media_item file_item <%= file["file_type"] %>_format" data-key="<%= key %>">
          <div class="thumb">
              <% case file["file_type"]  %>
              <% when "image"  %>
                  <img src="<%= file["thumb"] %>" alt="">
              <% when "audio"  %>
                  <i class="fa fa-file-audio-o"></i>
              <% when "video"  %>
                  <i class="fa  fa-film"></i>
              <% when "compress"  %>
                  <i class="fa fa-file-archive-o"></i>
              <% when "doc"  %>
              <% when "document"  %>
                  <i class="fa fa-file-text-o"></i>
              <% else  %>
                  <i class="fa fa-file-o"></i>
              <% end %>
          </div>
          <div class="label_thumb">
              <%= file["name"] %>
          </div>
          <textarea class="hidden data_value"><%= raw file.to_json %></textarea>
          <div class="actions">
              <% if file['file_type'] == 'image' && File.extname(file['name']).downcase != '.gif' %>
                <% args = {res: true, file: file}; hooks_run('file_manager_edit_file', args) %>  
                <% if args[:res] %>
                  <a href="#" class="edit_item btn btn-primary btn-xs" <%= 'data-permit-overwrite="true"' if @show_file_actions %>><i class="fa fa-pencil"></i></a>
                <% end %>
              <% end %>
              <% if @show_file_actions %>
                <% args = {res: true, file: file}; hooks_run('file_manager_del_file', args) %>
                <% if args[:res] %>
                  <a href="#" class="del_item btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                <% end %>
              <% end %>
          </div>
      </div>
    <% end %>
<% end %>